programming4us
           
 
 
Windows

Windows Azure : Programming Access Control Service (part 5)

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
12/4/2010 11:46:03 AM
1.5.6. Creating the Web Service Consumer

The web service client creates an SWT token with input claims and sends it to ACS to acquire an SWT token with output claims. The web service client packages this token into the header of the web service method call. The Client project in the Visual Studio solution contains the implementation of the web service client. Listing 8 shows the main method from Program.cs in the Client project.

Example 8. Main Method in Program.cs from the Web Service Client
static void Main()
{
Console.WriteLin("Enter your solution name, then press <ENTER>");
serviceNamespace = Console.ReadLine();

Console.WriteLine();
Console.WriteLine("Enter your issuer key, then press <ENTER>");
issuerKey = "K9GJNT96CQTL370TUnCyATOruMbnHVCLvb3RXO0g3z4=";
// create a token with a group=user claim
string userToken = GetUserToken();

// send the token to ACS
string acsIssuedToken = SendSWTToACS(userToken, "http://localhost/acsexample");

// perform the calculator operations
Console.WriteLine();
Console.WriteLine("Calling calculator with 'group=user' claim");
DoOperations(acsIssuedToken);

// create a token with a group=user,executive claim
string executiveToken = GetUserAdminToken();

// send the token to ACS
acsIssuedToken = SendSWTToACS(executiveToken, "http://localhost/acsexample");

// perform the calculator operations
Console.WriteLine();
Console.WriteLine("Calling ACS Example with 'group=user,admin' claim");
DoOperations(acsIssuedToken);

Console.WriteLine();
Console.WriteLine("Done. Press <ENTER> to end");
Console.ReadLine();
}


The GetUserToken() method creates an SWT token representing a user group and then calls the SendSWTToACS() method to get the SWT token from ACS that's specific to the user group. The code then calls the DoOperations() method, which calls all the operations on the ACSMachineInfo web service. Then, the GetUserAdminToken() method creates an SWT token that is sent to ACS to get an ACS-issued token for the admin group. The code then calls the DoOperations() method with the ACS-issued token. The output of the method calls should indicate when the particular group has enough permissions to call a web service method. The TokenFactory class contains the necessary logic to create an SWT token to be sent to ACS. Listing 9 shows the code to create an SWT token.

Example 9. Creating an SWT Token
public string CreateToken(Dictionary<string, string> claims)
{
// check for dup claimtypes
Dictionary<string, string> claimList = this.RemoveDuplicateClaimTypes(claims);

// build the claims string
StringBuilder builder = new StringBuilder();
foreach (KeyValuePair<string, string> entry in claimList)
{
builder.Append(entry.Key);
builder.Append('=');
builder.Append(entry.Value);
builder.Append('&');
}


// add the issuer name
builder.Append("Issuer=");
builder.Append(this.issuerName);
builder.Append('&');

// add the Audience
builder.Append("Audience=");
builder.Append(string.Format("https://{0}.{1}/WRAPv0.8&",
this.solutionName, this.acsHost));

// add the expires on date
builder.Append("ExpiresOn=");
builder.Append(GetExpiresOn(20));

string signature = this.GenerateSignature(builder.ToString(), this.signingKey);
builder.Append("&HMACSHA256=");
builder.Append(signature);

return builder.ToString();
}


You can see that creating an SWT token is very simple because you create only certain name/value pairs and POST them to the service namespace.

Other -----------------
- Windows 7 : Working with Registry Entries (part 3)
- Windows 7 : Working with Registry Entries (part 2)
- Windows 7 : Working with Registry Entries (part 1) - Changing the Value of a Registry Entry
- Windows 7 : Keeping the Registry Safe
- Windows 7 : Getting to Know the Registry (part 2)
- Windows 7 : Getting to Know the Registry (part 1) - Understanding Registry Settings
- Windows 7 : Firing Up the Registry Editor
- Windows Azure : Managing Access Control Service Resources (part 2)
- Windows Azure : Managing Access Control Service Resources (part 1)
- Windows Azure : Access Control Service Management Portal
- Windows 7 : Reset a Broken Service
- Windows 7 : Make Windows Shut Down Services Faster
- Windows 7 : Disable Services for Faster Performance
- Windows 7 : Controlling Services with a Script
- Windows 7 : Controlling Services at the Command Prompt
- Windows 7 : Controlling Services with the Services Snap-In
- Windows Azure : Access Control Service Usage Scenarios (part 3)
- Windows Azure : Access Control Service Usage Scenarios (part 2)
- Windows Azure : Access Control Service Usage Scenarios (part 1)
- Windows Azure : Access Control Service - Claims-Based Identity Model
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us